<?php
namespace app\common\model;
use think\Model;

class Base extends Model
{
    /**
     * 系统配置信息 By 类别 return 数组
     * @param int $_type
     * @return array $data
     */
    public function get_type_config($_type)
    {
        $data = [
            'type' => $_type
        ];
        return $this->where($data)->select();
    }

    /**
     * 系统配置项 By 类别 名称
     * @param $_type
     * @param $_name
     * @return string value
     */
    public function get_this_config_value($_type, $_name)
    {
        $data = [
            'type' => $_type,
            'name' => $_name
        ];
        return $this->where($data)->find();
    }

    public function get_this_data($id)
    {
        $data = [
            'id' => $id,
        ];
        return $this->where($data)->find();
    }

    /**
     * 根据id删除msg
     * @param int $id
     * @return boolean
     */
    public function del_msg($id)
    {
        $data = [
            'id' => $id
        ];
        return $this->where($data)->delete();
    }

    /**
     * 根据状态查询所有数据
     * @param int $status 0 隐藏 1 显示
     * @return array $data
     */
    public function get_status_all_msg($status)
    {
        $data = [
            'status' => $status
        ];
        return $this->where($data)->select();
    }

    /**
     * 仅用于首页展示数据限制
     * @param int $status
     * @param int $limit
     * @return array $data
     */
    public function limit_all_msg($status,$limit)
    {
        $data = [
            'status' => $status
        ];
        return $this->where($data)->paginate($limit);
    }

    public function limit_this_msg($limit,$key,$value)
    {
        $data = [
             $key    =>  $value,
        ];
        return $this->where($data)
                    ->where('status','neq','0')
                    ->paginate($limit);
    }

    /**
     * 仅用于首页展示数据限制
     * @param int $status
     * @param int $limit
     * @return array $data
     */
    public function limit_all_sort_msg($status,$limit,$value,$sort)
    {
        $data = [
            'status' => $status
        ];
        $order = [
            $value => $sort
        ];
        return $this->where($data)
                    ->order($order)
                    ->paginate($limit);
    }

    /**
     * @param int $NowPage 现在页码
     * @param int $limits 限制页码
     * @return array $data 专门处理ajax请求的表单数据
     */
    public function ajax_tree($NowPage,$limits,$keywords,$value)
    {
//        $data = [
//            'status'   => '1',
//        ];
//        $data = $this->where($data)
//            ->where($keywords,'like','%'.$value.'%')
//            ->page($NowPage,$limits)->select();
        $data = $this->where($keywords,'like','%'.$value.'%')
                     ->page($NowPage,$limits)->select();
        return $this->sort($data);
    }
}